package Tread;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class Example8_BlockingQueue {
    private static final BlockingQueue queue = new LinkedBlockingQueue<>();

    public static void main(String[] args) {
        Thread product = new Thread(() -> {
            try {
                System.out.println("Product:Producing");
                queue.put(1);
                System.out.println("Product is over");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        Thread consumer=new Thread(()->{
            try{
                System.out.println("consumer is waiting for product's over");
                int item= (int) queue.take();
                System.out.println("consumer:"+item);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        consumer.start();
        product.start();
    }
}
